package fge;

import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxICell;
import com.mxgraph.util.mxConstants;
import java.util.ArrayList;
import java.util.List;

public class IOport extends Fvertex
{
	static final int PORT_DIAMETER = 16;
	static final int PORT_RADIUS = PORT_DIAMETER / 2;
	private String type = "Unknown_type";

	public IOport() {
		super();
		
		// JGraph specifics
		this.setConnectable(true);	// Allow in or out-going edges
		this.changeStyle(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
		this.changeStyle(mxConstants.STYLE_FILLCOLOR, "white");
		this.changeStyle(mxConstants.STYLE_STROKEWIDTH, 2);
		this.changeStyle(mxConstants.STYLE_ROUNDED, 1);
		this.changeStyle(mxConstants.STYLE_OPACITY, 50);
		this.changeStyle(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_BOTTOM);
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	public List<mxCell> getIncomingEdges() {
		List<mxCell> ret = new ArrayList<mxCell>();
		
		for (int i = 0; i < this.getEdgeCount(); i++) {
			mxCell edge = (mxCell)this.getEdgeAt(i);
			mxICell edge_dst = edge.getTarget();
			if (edge_dst instanceof IOport) {
				if (((IOport)edge_dst).equals(this)) {	// Incoming edges must have this as their destination
					ret.add(edge);
				}
			}
		}
		
		return ret;
	}
	
	public List<mxCell> getOutgoingEdges() {
		List<mxCell> ret = new ArrayList<mxCell>();
		
		for (int i = 0; i < this.getEdgeCount(); i++) {
			mxCell edge = (mxCell)this.getEdgeAt(i);
			mxICell edge_src = edge.getSource();
			if (edge_src instanceof IOport) {
				if (((IOport)edge_src).equals(this)) {	// Outgoing edges must have this as their source
					ret.add(edge);
				}
			}
		}
		
		return ret;
	}
}
